From d38e4d31c9ec345a8fcba7ad40db45f0ab7a687d Mon Sep 17 00:00:00 2001 From: Nathanael Jones Date: Tue, 7 Feb 2017 19:12:48 -0700 Subject: [PATCH] Fix #3659 differently; sort HashMap keys before iteration. Reverts 7a8b25a (and the need for it) --- src/cargo/ops/cargo_compile.rs | 10 ++++++---- src/cargo/ops/cargo_rustc/custom_build.rs | 11 ----------- tests/build-script.rs | 2 +- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index acc2fdf35..ec3718955 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -492,7 +492,13 @@ fn scrape_target_config(config: &Config, triple: &str) rerun_if_changed: Vec::new(), warnings: Vec::new(), }; + // We require deterministic order of evaluation, so we must sort the pairs by key first. + let mut pairs = Vec::new(); for (k, value) in value.table(&lib_name)?.0 { + pairs.push((k,value)); + } + pairs.sort_by_key( |p| p.0 ); + for (k,value) in pairs{ let key = format!("{}.{}", key, k); match &k[..] { "rustc-flags" => { @@ -528,10 +534,6 @@ fn scrape_target_config(config: &Config, triple: &str) output.metadata.push((k.clone(), val.to_string())); } } - - // We randomized the data source with HashMaps, so we must sort the resulting vectors - // to produce a deterministic result - output.sort(); } ret.overrides.insert(lib_name, output); } diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index e187ab800..ea3e0f98c 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -406,17 +406,6 @@ impl BuildOutput { } Ok((library_paths, library_links)) } - - /// Sort the contents of the struct for consistent hashing. - /// Suggested if populated from a HashMap instead of an order-preserving data source - pub fn sort(&mut self){ - self.library_paths.sort(); - self.library_links.sort(); - self.cfgs.sort(); - self.metadata.sort(); - self.rerun_if_changed.sort(); - self.warnings.sort(); - } } /// Compute the `build_scripts` map in the `Context` which tracks what build diff --git a/tests/build-script.rs b/tests/build-script.rs index 5f4dee764..647b7a064 100644 --- a/tests/build-script.rs +++ b/tests/build-script.rs @@ -306,7 +306,7 @@ fn overrides_and_links() { [..] [..] [..] -[RUNNING] `rustc --crate-name foo [..] -L bar -L foo` +[RUNNING] `rustc --crate-name foo [..] -L foo -L bar` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ")); } -- 2.30.2